package com.itheima.d9_interface_demo;

import javax.sound.midi.Soundbank;
import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator {
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("打印所有学生信息");
        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            System.out.println("学生姓名" + student.getName() + ", 性别" + student.getGender() + "，成绩" + student.getScore());
            if (student.getGender() == '男') {
                count1++;
            } else if (student.getGender() == '女') {
                count2++;
            }
        }
        System.out.println("男生人数" + count1 + ", 女生人数" + count2);
        System.out.println("班级总人数" + students.size());
        System.out.println("------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double doubleAllScore = 0;
        int max = students.get(0).getScore();
        int min = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            if (student.getScore() > max)
                max = student.getScore();
            if (student.getScore() < min)
                min = student.getScore();
            System.out.println("最高分" + max + ", 最低分" + min);
            doubleAllScore += student.getScore();
        }
        System.out.println("学生最高分" + max + ", 最低分" + min);
        System.out.println("平均成绩" + (doubleAllScore - max - min / students.size()));

    }
}
